import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_state.dart';
import 'package:xm_app/common/http/api_response.dart';
import 'package:xm_app/common/logger/LoggerUtil.dart';
import 'package:xm_app/dao/VodDao.dart';
import 'package:xm_app/model/VodDetails.dart';

class VodDetailController extends GetxController with StateMixin<VodDetails> {
  final vodId = Get.parameters["id"];
  final vodDetail = VodDetails().obs;
  final appBarAlpha = 0.0.obs;
  @override
  void onInit() {
    super.onInit();
    getInfo();
  }

  getInfo() async {
    logDebug("VodDetailController getInfo");
    ApiResponse res = await VodDao().getVodInfo(int.parse(vodId));
    if (res.status == Status.ERROR) {
      SmartDialog.showToast(res.exception.message);
      change(null, status: RxStatus.error(res.exception.message));
      return;
    }
    vodDetail.value = res.data;
    change(vodDetail.value, status: RxStatus.success());
  }

  onScroll(offset) {
    //print(offset);
    if (offset > 100) {
      appBarAlpha.value = 1;
      return;
    }
    double alpha = offset / 100;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    appBarAlpha.value = alpha;
  }

  @override
  void onClose() {
    super.onClose();
    logDebug("VodDetailController onClose $vodId");
  }
}
